package roman.algorithm;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import roman.algorithm.Graph.Edge;
import roman.algorithm.Graph.Node;


public class Test {
	
	static Node[] nodes;
	static List<Edge> mst;
	static BinaryHeap<Edge> edges;
	static UnionFind uf;
	
	static void addEdge(int a, int b, int cost){
		edges.add(new Edge(a,b,cost));
		nodes[a].edges.add(new Edge(a,b,cost));
		nodes[b].edges.add(new Edge(b,a,cost));
	}
	
	public static void main(String[] argc){
		nodes = new Node[4];
		edges = new BinaryHeap<Edge>();
		uf = new UnionFind(nodes.length);
		mst = new LinkedList<Edge>();
		nodes[0] = new Node(0);
		nodes[1] = new Node(1);
		nodes[2] = new Node(2);
		nodes[3] = new Node(3);
		addEdge(0,1,2);
		addEdge(0,2,5);
		addEdge(0,3,1);
		addEdge(1,3,3);
		addEdge(2,3,4);
		Kruskal.kruskal(nodes.length, uf, mst, edges);
		int sum = 0;
		Iterator<Edge> it = mst.iterator();
		while(it.hasNext()){
			sum += it.next().cost;
		}
		System.out.println(sum);
	}
}
